﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data .Linq ;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DoAn
{
    public partial class frmDangNhap : Form
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }
        private static MyDataDataContext _DC = new MyDataDataContext();
        private App_Code.TaiKhoan taikhoan;
        public App_Code.TaiKhoan Taikhoan
        {
            get { return taikhoan; }
            set { taikhoan = value; }
        }
        //nut thoat
        private void btnThoat_Click(object sender, EventArgs e)
        {
            //
            this.Close();
            
        //    MainForm.mainform.Close();
//
        }

//        private void frmDangNhap_Load(object sender, EventArgs e)
  //      {

//        }

        private void btnDongY_Click(object sender, EventArgs e)
        {

            var query = from t in _DC.TAIKHOANs 
                        join n in _DC .NHANVIENs on t.MaNhanVien equals n.Ma into tn
                        from n in tn .DefaultIfEmpty ()
                        where  t.MatKhau== txtMatKhau.Text && t.TenTaiKhoan ==txtTenDangNhap.Text  
                        select new {t.TenTaiKhoan ,t.MatKhau ,n.MaChucVu  } ;
            
            if (query.Count() > 0)
            {
                int ma = query.AsEnumerable().ElementAt(0).MaChucVu;
                string  matkhau = query.AsEnumerable().ElementAt(0).MatKhau ;
                string tentaikhoan = query.AsEnumerable().ElementAt(0).TenTaiKhoan ;
                taikhoan = new DoAn.App_Code.TaiKhoan(matkhau, tentaikhoan, ma, true);
            }
            this.Close();





        }
    }
}
